home *** CD-ROM | disk | FTP | other *** search
/ Aminet 41 / Aminet 41 (2001)(Schatztruhe)[!][Feb 2001].iso / Aminet / dev / c / libiconv_src.lha / src / ces_big5.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-11-07  |  982 b   |  52 lines

  1.  
  2. /*
  3.  * BIG-5
  4.  */
  5.  
  6. static int
  7. ces_big5_mbtowc (conv_t conv, wchar_t *pwc, const unsigned char *s, int n)
  8. {
  9.   unsigned char c = *s;
  10.   /* Code set 0 (ASCII) */
  11.   if (c < 0x80)
  12.     return ascii_mbtowc(conv,pwc,s,n);
  13.   /* Code set 1 (BIG5) */
  14.   if (c >= 0xa1 && c < 0xff) {
  15.     if (n < 2)
  16.       return RET_TOOFEW(0);
  17.     {
  18.       unsigned char c2 = s[1];
  19.       if ((c2 >= 0x40 && c2 < 0x7f) || (c2 >= 0xa1 && c2 < 0xff))
  20.         return big5_mbtowc(conv,pwc,s,2);
  21.       else
  22.         return RET_ILSEQ;
  23.     }
  24.   }
  25.   return RET_ILSEQ;
  26. }
  27.  
  28. static int
  29. ces_big5_wctomb (conv_t conv, unsigned char *r, wchar_t wc, int n)
  30. {
  31.   unsigned char buf[2];
  32.   int ret;
  33.  
  34.   /* Code set 0 (ASCII) */
  35.   ret = ascii_wctomb(conv,r,wc,n);
  36.   if (ret != RET_ILSEQ)
  37.     return ret;
  38.  
  39.   /* Code set 1 (BIG5) */
  40.   ret = big5_wctomb(conv,buf,wc,2);
  41.   if (ret != RET_ILSEQ) {
  42.     if (ret != 2) abort();
  43.     if (n < 2)
  44.       return RET_TOOSMALL;
  45.     r[0] = buf[0];
  46.     r[1] = buf[1];
  47.     return 2;
  48.   }
  49.  
  50.   return RET_ILSEQ;
  51. }
  52.